package com.example.livestockbreedingapplication.slice;

import com.example.livestockbreedingapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.TextField;
import ohos.agp.window.dialog.ToastDialog;

public class SystemChangePwdSlice extends AbilitySlice implements Component.ClickedListener {

    TextField changePwd;
    TextField sureChangePwd;
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_system_change_password);
        Button sure = (Button)findComponentById(ResourceTable.Id_sure_change);
        Button back = (Button)findComponentById(ResourceTable.Id_back_to_login);
        changePwd = (TextField)findComponentById(ResourceTable.Id_change_password);
        sureChangePwd = (TextField)findComponentById(ResourceTable.Id_sure_change_password);
        sure.setClickedListener(this);
        back.setClickedListener(this);
    }

    @Override
    protected void onActive() {
        super.onActive();
    }

    @Override
    protected void onInactive() {
        super.onInactive();
    }

    @Override
    protected void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    protected void onBackground() {
        super.onBackground();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    public void onClick(Component component) {
        if (component.getId() == ResourceTable.Id_sure_change){
            if (changePwd.getText().equals("")||sureChangePwd.getText().equals("")){
                new ToastDialog(SystemChangePwdSlice.this)
                        .setText("修改密码不能为空！")
                        .show();
                return;
            }else if (changePwd.getText().equals(sureChangePwd.getText())){
                new ToastDialog(SystemChangePwdSlice.this)
                        .setText("两次输入的密码不一致！")
                        .show();
                return;
            }
            Intent intent = new Intent();
            intent.setParam("change","密码修改成功");
            setResult(intent);
            terminate();
        }
        if (component.getId() == ResourceTable.Id_back_to_login){
            Intent intent = new Intent();
            intent.setParam("change","未修改密码");
            setResult(intent);
            terminate();
        }
    }
}
